<template>
    <div class="wy-main business-car-manage">
      <a-row class="wy-main-title">
       <a-col :span="24">
        <p class="title-p">
          <a-divider class="title-vertical"  type="vertical" />
          <span class="title-span" >车辆认证审核</span>
          <a-divider class="title-divider"  />
        </p>
      </a-col>
   </a-row>
     <div class="my-main-cont" style="margin-left: 30px">
         <a-input v-model="licence" placeholder="请输入车牌号" style="width: 200px"/>
         <a-button type="primary" style="margin-left: 10px;" @click="getcarSource">查询</a-button>
		     <a-button style="margin-left: 15px;" @click="reset">重置</a-button>
         <a-button class="title-button" type="primary" @click="seeAllInfo()">批量审核</a-button>
         <div class="wei_car_vehcle">
           <a-table :columns="columns" :rowKey="record => record.vehicleId" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" @change="handleTableChange" :dataSource="cardata"  :pagination="pagination" :loading="loading" style="margin-top: 20px" >
  					 	<span slot="action" slot-scope="text, record">
  		          <a v-if="record.authenticationStatus==119" class="wei_warning" href="javascript:;" @click="edit(record)">待认证</a>
                <a v-if="record.authenticationStatus==120" class="wei_primary" href="javascript:;" @click="edit(record)">认证通过</a>
                <a v-if="record.authenticationStatus==121" class="wei_danger" href="javascript:;" @click="edit(record)">认证失败</a>
  		        </span>
               <span slot="releaseDateSplit" slot-scope="text, record">
                <span v-if="!!record.createTime">{{record.createTime.split(" ")[0]}}</span>

              </span>
              
           </a-table>
          </div>
        <!--   <div style="margin-top: -50px">
            <a-button @click="delAll">删除所选</a-button>
          </div> -->
     </div>
		 <a-modal :title="type == 'edit' ? '车源审核' : '查看车源信息'" :visible="visible" @cancel="handleCancel" width="900px" :maskClosable='false' :footer="null" >
			  <vehicle-add v-if="visible" :datail='datail' @close="close" :type='type'></vehicle-add>
		 </a-modal>
      <a-modal title="车辆审核" :visible="visibleAll"  @cancel="handleCancel"  width="900px" :maskClosable='false' :footer="null" >
       <vehicle-add-all v-if="visibleAll" @cancel="handleCancel" :datailAll='datailAll'></vehicle-add-all>
      </a-modal>
    </div>
</template>
<script>
import vehicleAdd from './VehicleAdd'
import vehicleAddAll  from './VehicleAddAll'
const columns = [{
    title: '车牌号',
    dataIndex: 'licence',
    key: 'licence',
    scopedSlots: {
      customRender: 'licence'
    },
  },{
		title: '车辆类型',
		dataIndex: 'typeValue',
		key: 'typeValue',
	},{
		title: '车长',
		dataIndex: 'length',
		key: 'length',
	},{
    title: '载重',
    dataIndex: 'weight',
    key: 'weight',
  },{
		title: '车辆常驻地',
		dataIndex: 'residence',
		key: 'residence',
	},{
		title: '提交日期',
		dataIndex: 'createTime',
		key: 'createTime',
      scopedSlots: {
      customRender: 'releaseDateSplit'
    },
	},
	{
		title: '操作',
		key: '0',
		scopedSlots: {
			customRender: 'action'
		},
	}];

const rowSelection = {
  onChange: (selectedRowKeys, selectedRows) => {
    console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  },
  onSelect: (record, selected, selectedRows) => {
    console.log(record, selected, selectedRows);
  },
  onSelectAll: (selected, selectedRows, changeRows) => {
    console.log(selected, selectedRows, changeRows);
  },
};
export default {
    
    data() {
        return {
				type: '',
				visible: false,
        visibleAll:false,
         columns,
				 cardata:[],
				 datail: {},
         loading: false,
         licence: '',
         rowSelection,
         selectedRowKeys: [],
        pagination: {
          pageSizeOptions: ['10', '20', '30', '40', '100'],
          defaultCurrent: 1,
          defaultPageSize: 10,
          total:10,
          showSizeChanger: true,
          showTotal: (total, range) => `共 ${total} 条记录`
        },
        }
    }, 
    created() {
      this.getcarSource()
		},
		components: {
			vehicleAdd,
      vehicleAddAll
		},
    methods: {
			//修改完毕刷新数据
				close(){
				this.visible = false
				this.getcarSource()
			},
      //选择参数
      seeAllInfo(){
        if(this.selectedRowKeys.length){
            this.visibleAll = true;
            let logIds = [];
           for(var i=0;i<this.selectedRowKeys.length;i++){
            logIds.push({"vehicleId":this.selectedRowKeys[i]})
           }
            this.datailAll = logIds;
          }else{
            this.$message.success('请选择需要审核的车辆!')
          }
      
      },
      onSelectChange (selectedRowKeys) {
          console.log('selectedRowKeys changed: ', selectedRowKeys);
          this.selectedRowKeys = selectedRowKeys
      },
			//审核货物信息
			edit(data){
				this.type = 'edit'
				this.visible = true
		    this.datail = data
			},
				// 关闭弹窗
			handleCancel(){
				this.visible = false
        this.visibleAll = false
         this.selectedRowKeys=[];
         this.getcarSource();
			},

			
			//删除
			delAll() {
				this.$confirm({
					title: '确定删除所选中的记录？',
					content: '当您点击确定按钮后，这些记录将会被彻底删除',
					centered: true
				})

			},
      //重置
      reset () {
				this.pagination.defaultCurrent = 1;
				this.licence = '';
				this.getcarSource();
			},
			
			//获取车源信息
				getcarSource(params={}){
				this.loading = true
				// params.licence = this.licence
				params.pageSize = this.pagination.defaultPageSize
				params.pageNum = this.pagination.defaultCurrent
				// params.licence= this.licence
				this.$get('/info/infoVehicle', {
          pageSize: this.pagination.defaultPageSize,
          pageNum: this.pagination.defaultCurrent,
           licence:this.licence
        }).then((r) => {
					this.loading = false
					console.log(r)
					this.cardata = r.data.data.rows
          this.pagination.total = r.data.data.total
				})
			},
            // 表格排序 分页 筛选事件
      handleTableChange(pagination, filters, sorter) {
         this.pagination.defaultPageSize = pagination.pageSize
         this.pagination.defaultCurrent  = pagination.current
         this.getcarSource();
        // this.getcarSource({
        //   ...this.queryParams
        // })
      },
    }
}
</script>
<style lang="less">
.title-button{
    float:right;

}
</style>
